package com.atguigu.spzx.manger.controller;

import com.atguigu.spzx.manger.service.SysMenuService;
import com.atguigu.spzx.model.entity.system.SysMenu;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/system/sysMenu")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;


    /**
     * 根据id删除菜单
     * @param id
     * @return
     */
    @DeleteMapping("/removeById/{id}")
    public Result removeById(@PathVariable Long id ){
        sysMenuService.removeById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }


    /**
     * 修改菜单
     * @param sysMenu
     * @return
     */
    @PutMapping("/updateById")
    public Result updateById(@RequestBody SysMenu sysMenu){
        sysMenuService.updateById(sysMenu);

        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 新增菜单
     * @param sysMenu
     * @return
     */
    @PostMapping("/save")
    public Result save(@RequestBody SysMenu sysMenu){
        sysMenuService.save(sysMenu);

        return Result.build(null,ResultCodeEnum.SUCCESS);

    }

    /**
     * 查询所有菜单数据
     * @return
     */
    @GetMapping("/findNodes")
    public Result<List<SysMenu>> findNodes(){

        List<SysMenu> sysMenuList=sysMenuService.findNodes();

        return Result.build(sysMenuList, ResultCodeEnum.SUCCESS);
    }
}
